package proxyTest.serverProxy.client;

import io.netty.channel.*;

import java.util.concurrent.TimeUnit;

/**
 * @Author: jia
 * @Descirption:
 * @Date: 2018/5/16 14:06
 * @Modified By:
 */


public class Client2ServerHandler extends SimpleChannelInboundHandler {
    @Override
    protected void channelRead0(final ChannelHandlerContext ctx, Object o) throws Exception {
        System.out.println("代理客户端收到的消息===" + o);
        EventLoop eventLoop = ctx.channel().eventLoop();
        eventLoop.schedule(new Runnable() {
            @Override
            public void run() {
                ctx.channel().writeAndFlush("你好,我是代理客户端");

            }
        },5, TimeUnit.SECONDS);
        //ctx.read();
  /*      ChannelPipeline pipeline = ctx.pipeline();
        ChannelFuture future = pipeline.write(o);
        //处理异常，也可以在outboudHandler中的read方法处理，给promise添加监听器
        future.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture cf) throws Exception {
                if (cf.isSuccess()) {
                    cf.cause().printStackTrace();
                    cf.channel().close();
                }
            }
        });*/
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        super.channelReadComplete(ctx);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        super.channelRead(ctx, msg);
    }
}
